package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.customer.entity.Customer;
import com.ibiaoke.marketing.consts.CouponReceiveConsts;
import com.ibiaoke.marketing.entity.CouponReceive;
import com.ibiaoke.marketing.service.CouponReceiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by SuXin on 2017/6/26.
 */
@Controller
public class WxCouponController extends BaseController{


    @Autowired
    private CouponReceiveService couponReceiveService;

    /**
    * 个人优惠券查询
    * @param type 查询类型： 可用的、已用过的、过期的
    * @return res
    * */
    @RequestMapping("/listCoupon")
    @ResponseBody
    public Res listCoupon(Integer type) {
        Customer customer = getLoginUser();
        AssertUtils.notNull(customer, "请登录");
        List<CouponReceive> couponList = couponReceiveService.listCouponReceiveByType(customer.getCustomerId(), type);
        return new Res().addResponse("couponList",couponList);
    }

    /**
    * 查询符合订单的可用优惠券
    * @Param fullPrice
    * @return res
    * */
    @RequestMapping("/listCouponByOrderPrice")
    @ResponseBody
    public Res listCouponByOrderPrice(BigDecimal fullPrice,String goodsIds) {
        Customer customer = getLoginUser();
        AssertUtils.notNull(customer, "请登录");
        List<CouponReceive> couponList = couponReceiveService.listCouponReceive(customer.getCustomerId(), fullPrice,goodsIds);
        return new Res().addResponse("couponList",couponList);
    }

    /**
     * 查询可用优惠券的数量
     *
     * @return
     */
    @RequestMapping("/getCouponNum")
    @ResponseBody
    public Res getCouponNum() {
        Customer customer = getLoginUser();
        AssertUtils.notNull(customer, "请登录");
        List<CouponReceive> couponList = couponReceiveService.listCouponReceiveByType(customer.getCustomerId(), CouponReceiveConsts.AVAILABLE);
        return new Res().addResponse("availableCouponNum", couponList.size());
    }
}
